package com.example.mardan_demo1.controller;


import com.example.mardan_demo1.pojo.Result;
import com.example.mardan_demo1.service.BgsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.time.LocalDate;

/**
 * @Author:买尔旦江 ×@CreateTime: 2024-11-22
 * @Description: 报告书控制器/ 用apifox
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/bgs_user")
public class BgsController {
    @Autowired
    private BgsService bgsService;
    @InitBinder
    public void initBinder(WebDataBinder binder) {
        binder.registerCustomEditor(LocalDate.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
    }

    @PostMapping("/hello")
    public Result hello() {
        return Result.success("hello");
    }
    /*
     * @Description: 获取所有处理过的日志，用于给管理员查询，以及统计总数
     * @Author:  买尔旦江
     * @date:  2024/11/27 13:54
     */
    @PostMapping("/count")
    public Result countLogs(Integer pageSize, Integer pageNum) {
        return bgsService.countLogs(pageSize, pageNum);
    }

    /*
     * @Description: 用户查看管理员待审核的报告
     * @Author:  买尔旦江
     * @date:  2024/11/26 20:51
     */

    /**
     * ApiName:获取管理员待审核数据
     * ApiDes:
     * @param pageSize 分页大小
     * @param pageNum 页码
     * @return 响应描述： Bgs_log
     */
    @PostMapping("/guan_li_dai_shen")
    public Result guanli_dai_shen(Integer pageSize, Integer pageNum) {
        return bgsService.guanli_dai_shen(pageSize, pageNum);
    }

    /*
     * @Description: 管理员审批用户申请的归还请求，同意
     * @Author:  买尔旦江
     * @date:  2024/11/26 13:29
     */
    @PostMapping("/gui_huan_shen_pi")
    public Result guiHuanShenPi(Integer log_id) {
        return bgsService.guiHuanShenPi(log_id);
    }

    /*
     * @Description: 管理员获取用户归还申请表
     * @Author:  买尔旦江
     * @date:  2024/11/26 13:14
     */
    @PostMapping("/gui_huan_shen_qing_liebiao")
    public Result guiHuanShenQingLieBiao(Integer pageSize, Integer pageNum) {
        return bgsService.guiHuanShenQingLieBiao(pageSize, pageNum);
    }

    /*
     * @Description: 客户归还报告书申请，判断是否为客户权限，判断是否这个人在使用，
     * @Author:  买尔旦江
     * @date:  2024/11/23 22:40
     */
    @PostMapping("/gui_huan_shen_qing")
    public Result guiHuanShenQing(Integer log_id) {
        return bgsService.guiHuanShenQing(log_id);
    }
    /*
     * @Description: 用户获取当前属于自己借阅的报告列表
     * 首先，userId 为该用户的id
     * 其2：借阅处理意见是同意，归还处理意见为空
     * @Author:  买尔旦江
     * @date:  2024/11/23 18:20
     */
    @PostMapping("/get_own_list")
    public Result getOwnList(Integer pageSize, Integer pageNum) {
        return bgsService.getOwnList(pageSize, pageNum);
    }
    
    
    /*
     * @Description: 客户查看借阅日志
     * @Author:  买尔旦江
     * @date:  2024/11/23 14:47
     */
    @PostMapping("/bgs_jieYue_log")
        public Result bgs_jieYue_log(Integer bgs_id,Integer pageSize, Integer pageNum) {
            return bgsService.bgs_jieYue_log(bgs_id, pageSize, pageNum);
        }

    /*
     * @Description: 管理员同意借阅
     * @Author:  买尔旦江
     * @date:  2024/11/23 14:31
     */
    @PostMapping("/tongYi_jieYue")
    public Result handleJieYue(Integer user_id, Integer bgs_id, Integer bgs_log_id, String isReject) {
        return bgsService.handleJieYue(user_id, bgs_id, bgs_log_id, isReject);
    }



    /*
     * @Description: 管理员查看报告书申请列表
     * @Author:  买尔旦江
     * @date:  2024/11/23 1:00
     */
    @PostMapping("/shenqingliebiao")
    public Result shenqingliebiao(Integer pageSize, Integer pageNum) {
        return bgsService.shenQingLieBiao(pageSize, pageNum);
    }



    /*
     * @Description: 客户获取报告书列表
     * @Author:  买尔旦江
     * @date:  2024/11/23 0:59
     */

    @PostMapping("/list")
    public Result list(String bgs_code, String bgs_name, Integer pageSize, Integer pageNum) {
        return bgsService.list(bgs_code, bgs_name, pageSize, pageNum);
    }
    /*
     * @Description: 客户申请借阅报告书
     * @Author:  买尔旦江
     * @date:  2024/11/23 0:59
     */

    @PostMapping("/jieyue")
    public Result jieyue(Integer bgs_id, String j_sq_message) {
        return bgsService.jieyue(bgs_id, j_sq_message);
    }
}
